function subCheck(){
	if($("#startDate").length > 0  && $("#endDate").length > 0){
		var startDate = $("#startDate").val();
		var endDate = $("#endDate").val();
		if(startDate == ""){
			alert("请选择开始时间!");
			if(!($($('#selectTitle .biui-add-btn')[0]).hasClass('active')))
            {
			$($('#selectTitle .biui-add-btn')[0]).click();
		    }
			return false;
		}
		if(endDate == ""){
			/*$('#datewarning').show();*/
			alert("请选择结束时间!");
			if(!($($('#selectTitle .biui-add-btn')[0]).hasClass('active')))
            {
			$($('#selectTitle .biui-add-btn')[0]).click();
		    }
			return false;
		}
		if(startDate > endDate){
			alert("开始时间不能大于结束时间！");
			if(!($($('#selectTitle .biui-add-btn')[0]).hasClass('active')))
            {
			$($('#selectTitle .biui-add-btn')[0]).click();
		    }
			return false;
		}

		var isMonthSearch = $("#isMonthSearch").val();
		if(isMonthSearch == 0 ){
			startDate = startDate.substring(0,startDate.lastIndexOf('-'));
			endDate = endDate.substring(0,endDate.lastIndexOf('-'));
			if(startDate != endDate){
				alert("本报表不支持跨月查询!");
			if(!($($('#selectTitle .biui-add-btn')[0]).hasClass('active')))
            {
			$($('#selectTitle .biui-add-btn')[0]).click();
		    }
				return false;
			}
		}

	}

	if($("#searchDate").length > 0 ){
		var searchDate = $("#searchDate").val();
		if(searchDate == ""){
			alert("请选择查询时间!");
			if(!($($('#selectTitle .biui-add-btn')[0]).hasClass('active')))
            {
			$($('#selectTitle .biui-add-btn')[0]).click();
		    }
			return false;
		}
	}
    $("form").removeAttr('target');
    return true;
}
function sub(){
	var formname = $("#formname").val();

	if(sendgroupby())
	{
	  if($("#down").val()!=1)
	   {
	   	$.blockUI({ message: '<img src="/image/newui/loading.gif" />' });//<button id="blockclear" onclick="$.unblockUI()">关闭</button>
	    $("#"+formname).submit();
	   }else
	   {
	   	var ttleng=parseInt($("#querylengthfordown").val());
	   	var maxDatas = 5000000;
	   	if(ttleng>maxDatas)
	   	{
	   		var info = "您导出的数据量过大，本系统最大支持"+maxDatas+"行数据导出，请修改查询条件并重新导出！";
	   		alert(info);
	   	}else if(ttleng>500000)
	   	{
	   		$("#downdata").show();
		    $('.panelhidden-bg').show();
	   		/*var downInfo = "您导出的数据共有"+ttleng+"行，因数据量过大，我们将缓冲后发送到您的下载列表中。";
	   		if(confirm(downInfo))
	   			{
			   		jQuery.ajax({
		            type:"POST",
		            dataType:"json",
		            async:true,
		            url:"/irtools/userSubMail",
		            data:{"reportId":$("#reportId").val()},
		            success:function(data){
			               if(data.result == "success"){
						   		alert("正在缓冲中，请耐心等待并注意到我的下载中下载！");
						   }else{
						 		alert("发送失败，请重新选择！");
						   }
			            }
			       	 });
	   			}else{
	   				alert("您已取消！请缩小范围后再查询！");
	   			};*/
	   	}else{
	   		$("#"+formname).submit();
	   	}

	   }

	}
}
$(function(){
	$("#tosearch").click(function(){
		//如果group存在执行下面函数$('#groupBy')selectTitle2
		if((document.getElementById("ui-tab")!=undefined)&&($("#colsSelect").val()=="")){
	    		alert("请选择指标，指标不能为空！");
	    		if(!($($('#selectTitle .biui-add-btn')[$('#selectTitle').find('.biui-add-btn').length-1]).hasClass('active')))
                {
			     $($('#selectTitle .biui-add-btn')[$('#selectTitle').find('.biui-add-btn').length-1]).click();
		        }

	    }else if(subCheck()){
	        /*如果有城市，添加城市 citypredone();*/
    		$('#selectBox .biui-select-box').hide();
	        $('#selectTitle .biui-add-btn').removeClass('active');
	        $('#emailsubsend').show();
			$("#ordervalue").val("");
			$("#ordertype").val("");
	    	$("#down").val(0);
			//查询记录入库
			jQuery.ajax({
		        type:"post",
		        async:true,
		        url:"/irtools/searchrecord",
		        data:{"pathId":$("#pathId").val(),"groupBy":$("#groupBy").val(),"searchCols":$("#colsSelect").val(),"templateType":$("#templateType").val()},
		        success:function(data){

		        }
		 	});
			//提交查询
			sub();
		}
	});
});

$(function(){
	$("#emailsubsend").click(function(){

		$('#mailsend').show();
		$('.panelhidden-bg').show();
	});
	$(".close-mail").click(function(){
		$('.mail').hide();
		$('.panelhidden-bg').hide();
	});
	$(".close-chart").click(function(){
		$('.chartviews').hide();
	});
});

$(function(){
	$("[clickname='suborder']").click(function(){
    	$("#down").val(0);
    	$("#ordervalue").val($(this).attr('columnname'));
		var ordertype = $(this).find('i').attr('class');
		if(ordertype=='tableup')
            $("#ordertype").val('asc');
    	else
    		$("#ordertype").val('desc');
		if(subCheck()){
			sub();
		}


	});
});
function selectRatio(elem){
	$("#down").val(0);
     if(subCheck()){
			sub();
		}
}
function selectDaily(elem){
	$("#down").val(0);
	$("#rijun").val(1);
     if(subCheck()){
			sub();
		}
}
$(function(){
	$("#download").click(function(){
		$("#down").val(1);
		if(subCheck()){
			sub();
		}
		rescheckgroup();

	});
});


function addchvalues(value){
		var chartvalues = $("#chartvalues").val();
		var fs = chartvalues.split(",");
		var newfs ="";
		var flag = false;
		for(var i=0;i<fs.length;i++){
			var f = fs[i];
			if(f!=""){
				if(f == value){
				  flag = true;
				  continue;
				}
				newfs = newfs + f+",";
			}
		}
		if(!flag){
			newfs = newfs + value+",";
		}
		$("#chartvalues").val(newfs);
	}


 $(function(){$("#pieshow").click(function(){
		 		var chartvalues = $("#chartvalues").val();
		 		if("" == chartvalues){
					alert("请选择绘图指标！");
					return false;
				}

				if(chartvalues.lastIndexOf(",")+1 == chartvalues.length){
					chartvalues = chartvalues.substring(0,chartvalues.lastIndexOf(","));
				}

				var fs = chartvalues.split(",");
				if(fs.length > 1){
					alert("最多只能选择1个指标进行绘图！");
					return false;
				}

				var formname = $("#formname").val();
				var pathId  = $("#pathId").val();
				$("#chartvalues").val(chartvalues);
				$("#chartType").val(2);
            	jQuery.ajax({
        			url:"/intreport/chartsearch/"+pathId,
            		type:"post",
            		async:true,
					dataType:"json",
            		data:$('#'+formname).serialize(),
            		success:function(cc){
						var data = cc.result;
                		if(data == "error" || data == ""){
							alert("error!");
						}else{
						  var chart ;
						  var chart = new FusionCharts("/image/swf/fusionChartsCracker.swf?chartUrl=/image/swf/Pie3D.swf", "ChartId", "800", "500", "0", "0");
						  var xml = data;
						  chart.setDataXML(xml);
					      chart.render("chartdiv");
						}
            		}
            	});
        	 })
})


function formatDate(oldDate) {
	var dates = oldDate.split("-");
	var newDate = dates[0];

	for(var i = 1;i < dates.length; i++){
		var temp = dates[i];
		if(temp < 10){
			newDate = newDate+"-0"+temp
		}else{
			newDate = newDate+"-"+temp
		}
	}

	return newDate;
}

function selectDate(dayNum){
    var endDate = new Date();
    var finalendDate=new Date(endDate.valueOf() - 1*24*60*60*1000);
	var startDate = "";
	if(dayNum == "-1"){
		var uom = new Date(new Date()-0+(-1)*86400000);
		startDate = uom.getFullYear() + "-" +  (uom.getMonth()+1) + "-" + uom.getDate();
	}else if(dayNum == "-7"){
		var uom = new Date(new Date()-0+(-7)*86400000);
		startDate = uom.getFullYear() + "-" +  (uom.getMonth()+1) + "-" + uom.getDate();
	}else if(dayNum == "-1m"){
		if(endDate.getMonth() == 0){
			startDate = endDate.getFullYear()-1 + "-12-" + endDate.getDate();
		}else{
			startDate = endDate.getFullYear() + "-" + endDate.getMonth() + "-" + endDate.getDate();
		}
	}

    finalendDate = finalendDate.getFullYear() + "-" +  (finalendDate.getMonth()+1) + "-" + finalendDate.getDate();

	startDate = formatDate (startDate);
	finalendDate = formatDate (finalendDate);
	var isMonthSearch = $("#isMonthSearch").val();
		if(isMonthSearch == 0 ){
			var sDate = startDate.substring(0,startDate.lastIndexOf('-'));
			var eDate = finalendDate.substring(0,finalendDate.lastIndexOf('-'));
			if(sDate != eDate){
				alert("本报表不支持跨月查询!");
				return false;
			}
		}
	$("#endDate").val(finalendDate);
	$("#startDate").val(startDate);
}

/**？？？**/
$(function(){
   $("#dpChannelName").change(function(){
      var channelName = $("#dpChannelName").val();
      if(channelName != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/discate",
        data:{"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateOneList = "";
    		  cateOneList = "<option value=''>全部</option>";
              $.each(data.discateListOne, function(i, obj) {
                 cateOneList = cateOneList + "<option value='"+obj.cate1+"'>"+obj.cate1+"</option>";
              });
              $("#dpCateOne").empty().append(cateOneList);

			  var cateThreeList = "<option value=''>全部</option>";
			  $("#dpCateTwo").empty().append(cateThreeList);
			  $("#dpCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#dpCateOne").empty().append(cateList);
		  $("#dpCateTwo").empty().append(cateList);
		  $("#dpCateThree").empty().append(cateList);
	  }
    });
});

/**？？？**/
$(function(){
   $("#bcChannelName").change(function(){
      var channelName = $("#bcChannelName").val();
      if(channelName != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/belongcate",
        data:{"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateOneList = "";
    		  cateOneList = "<option value=''>全部</option>";
              $.each(data.belongcateListOne, function(i, obj) {
                 cateOneList = cateOneList + "<option value='"+obj.cate1+"'>"+obj.cate1+"</option>";
              });
              $("#bcCateOne").empty().append(cateOneList);

			  var cateThreeList = "<option value=''>全部</option>";
			  $("#bcCateTwo").empty().append(cateThreeList);
			  $("#bcCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#bcCateOne").empty().append(cateList);
		  $("#bcCateTwo").empty().append(cateList);
		  $("#bcCateThree").empty().append(cateList);
	  }
    });
});

function setStatDate(statDate){
    var startDate = $("#startDate");
    var endDate = $("#endDate");
    var searchDate = $("#searchDate");
    if(startDate){
        startDate.val(statDate);
    }
    if(endDate){
        endDate.val(statDate);
    }
    if(searchDate){
        searchDate.val(statDate);
    }

}

$(function(){
	$("div[name='tab']").each(function(){
		checkSelectAll(this);
	});
});


function checkSelectAll(tabDiv){
		var allCheck=$(tabDiv).find(":checkbox[name='selectAllCol']");
		var isAll=true;
		$(tabDiv).find(":checkbox[name='selectCol']").each(function(){
			if(!$(this).is(':checked')){
				isAll=false;
				return false;
			}
		});
		if(isAll)
			allCheck.prop('checked',true);
}

//全选
function selectAllCols(cell){
	var isCheck = $(cell).is(':checked');
	var thisTab = $(cell).closest('[name="tab"]');
	thisTab.find('[name="selectCol"]').prop('checked',isCheck);
	setColsSelect();
}

//选择一个
function addSelect(cell){
	var isCheck = $(cell).is(':checked');
	if(!isCheck)
		$(cell).closest('[name="tab"]').find('#selectAllCol').prop('checked',isCheck);
	checkSelectAll($(cell).closest("div[name='tab']"));//检查是否应该全选
	setColsSelect();
}
function removeSelect(){
	$("div[name='tab']").find(":checkbox").prop('checked',false);
	$("#colsSelect").val("");
}
//设置所选指标选项值
function setColsSelect(){
	var cols = "";
	var checkboxs = document.getElementsByName("selectCol");
	for (var i = 0;i<checkboxs.length; i++) {
 		 var e = checkboxs[i];
		 if(e.checked){
    	 	cols = cols + e.value + ",";
    	 }
 	}
	$("#colsSelect").val(cols);
}


function dataCompare(){
	var cols = "";
	var checkboxs = document.getElementsByName("dcc");
	for (var i = 0;i<checkboxs.length; i++) {
 		 var e = checkboxs[i];
		 if(e.checked){
    	 	cols = cols + e.value + ",";
    	 }
 	}
	$("#compareSelect").val(cols);
}


function sendFre(id){
	var value = "";
	if(id == 1){
		value = "day";
	}else if(id == 2){
		value = "week";
	}
	$("#freValue").val(value);
}


$(function(){
   $("#subMail").click(function(){

   	  var ads = $("#emailAds").val();
   	  if("" == ads){
   	  	alert("订阅地址不能为空");
   	  	return false;
   	  }else{
   	  	var adsp = ads.split('/');
   	  	for(var i=0;i<adsp.length;i++){
   	  		if(!(adsp[i].indexOf('@58.com') != -1||adsp[i].indexOf('@58ganji.com') != -1||adsp[i].indexOf('@zhiyou.ganji.com') != -1||adsp[i].indexOf('@ganji.com') != -1||adsp[i].indexOf('@doumi.com') != -1)){
   	  			alert("邮箱只可为公司企业邮箱");
   	  			return false;
   	  		}
   	  	}
   	  }

 	  var freValue = $("#freValue").val();
	  if("" == freValue){
	  	alert("请选择发送频率!");
		return false;
	  }else{
	  	$('#mailsend').hide();
		$('#panelclose').hide();
      	jQuery.ajax({
            type:"POST",
            dataType:"json",
            async:true,
            url:"/irtools/reportSubMail",
            data:{"emailAds":$("#emailAds").val(),"freValue":freValue,"subName":$("#subName").val(),"reportId":$("#reportId").val()},
            success:function(data){
               if(data.result == "success"){
			   		alert("订阅成功！");
			   }else{
			 		alert("订阅失败，请重新订阅！");
			   }
            }
       	 });
	  }
    });
     $("#DownsubData").click(function(){
      var downname = $("#DownsubName").val();
   	  if("" == downname){
   	  	alert("下载别名不能为空");
   	  	return false;
   	  }
      $('#downdata').hide();
	  $('#panelclose').hide();
      jQuery.ajax({
		            type:"POST",
		            dataType:"json",
		            async:true,
		            url:"/irtools/userSubMail",
		            data:{"DownsubName":downname,"reportId":$("#reportId").val()},
		            success:function(data){
			               if(data.result == "success"){
						   		alert("正在缓冲中，请耐心等待，并注意查收完成提示邮件！");
						   }else{
						 		alert("发送失败，请重新选择！");
						   }
			            }
			       	 });
     });
});




$(function(){
	$("#dayRatio,#weekRatio").click(function(){
		if($(this).attr("disabled")==true)
			return;
		else
			addComp($(this).attr("id"));
	});
});

function sendInfo(url){
	$.ajax({
        url: "/irtools/visitrecord",
        type: 'GET',
        async:true,
        dataType: 'text',
        data: "&url="+encodeURIComponent(url),
        cache:false,
        success: function(json){
		}
});
}
sendInfo(document.URL);




var zhongxiao=['菏泽','临汾','枣庄','晋城','张家口','大同','濮阳','周口','滨州','绥化','丹东','揭阳','盘锦','承德','葫芦岛','宜宾','运城',
			'长治','晋中','四平','遂宁','清远','鸡西','宿迁','白城','朝阳','驻马店','达州','辽阳','本溪','茂名','贵港','安康','萍乡',
			'通辽','铁岭','乌海','鄂州','随州','韶关','益阳','资阳','广安','抚州','伊春','咸宁','黑河','梅州','贺州','双鸭山',
			'潮州','兴安盟','巴中','黔东南','延安','锡林郭勒','黔南','中卫','铜川','张家界','阿克苏','沭阳','阳春',
			'河池','商洛','雅安','汕尾','哈密','铜仁','白山','来宾','防城港','喀什','大兴安岭','仙桃','七台河',
			'固原','海拉尔','潜江','百色','云浮','湘西','阿拉善盟','那曲','甘孜','张北','黔西南','天门',
			'博尔塔拉','崇左','阿坝','海西','神农架','昌都','果洛','黄南','海南','海东','香港','林芝','海北','山南',
			'三沙','玉树','台湾','澳门','阿里','阿拉尔','五指山','日喀则','马来西亚','新加坡','泰国','衢州','阜新',
			'汉中','鹤壁','怀化','济源','郴州','娄底','莱芜','攀枝花','三门峡','邵阳','孝感','阳泉','通化','梧州','钦州','忻州','朔州','吴忠',
			'呼伦贝尔','吕梁','河源','广元','巴彦淖尔市','辽源','丽水','玉林','乌兰察布','景德镇','阳江','永州','眉山','鹤岗','凉山','恩施'];
var zhiying=['北京', '成都', '重庆', '石家庄', '济南', '青岛','南京', '杭州', '苏州', '无锡', '合肥',	'武汉', '郑州', '长沙', '福州',
				'厦门', '南宁', '哈尔滨', '长春', '太原', '大连', '沈阳','上海', '天津', '广州', '深圳', '东莞'];



function setCitySpe(cityArr,citytype){
       var selectcity="";
      for(var i=0;i<cityArr.length;i++)
	   {
	      $("select[name='"+citytype+"']").find("option[value='"+cityArr[i]+"']").prop('selected', true).attr('selected', 'selected');
       }
        $('#'+citytype+'').selectpicker('refresh');
 }
function unsetCitySpe(cityArr,citytype){
       var selectcity="";
      for(var i=0;i<cityArr.length;i++)
	   {
	      $("select[name='"+citytype+"']").find("option[value='"+cityArr[i]+"']").prop('selected', false).removeAttr('selected');;
       }
        $('#'+citytype+'').selectpicker('refresh');
 }

function removeCityTwo(IDSuffix){
		  $("#cityTwo_"+IDSuffix).empty();
		  $("#cityThree_"+IDSuffix).empty();

		  $("#cityTwo_"+IDSuffix).selectpicker('refresh');
		  $("#cityThree_"+IDSuffix).selectpicker('refresh');

		  $("#"+IDSuffix+"CityTwo").val('');
		  $("#"+IDSuffix+"CityThree").val('');
}

function removeCityThree(IDSuffix){
		  $("#cityThree_"+IDSuffix).empty();
		  $("#cityThree_"+IDSuffix).selectpicker('refresh');
		  $("#"+IDSuffix+"CityThree").val('');
}

function changeCityTwo(city1,type){
	var reqUrl = '';
	var IDSuffix = 'dl';
	var listName='';
	if(type == "dl"){
		reqUrl = "/irtools/displaylocal";
		listName="disCityListTwo";
	}
	else if(type == "bl"){
		reqUrl = "/irtools/belongcity";
		IDSuffix="bl";
		listName="belongCityListTwo";
	}
	if(city1 != "" && city1 !="zycitys" && city1 !="zscitys" ){
      	jQuery.ajax({
      		type:"post",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:{"city1":city1},
        	success:function(data){
          	if(data!="" && data.result =="right"){
             	var cityTwoList = "";
              	$.each(data[listName], function(i, obj) {
                 	cityTwoList = cityTwoList + "<option value='"+obj.localName+"'>"+obj.localName+"</option>";
              	});
              	$("#cityTwo_"+IDSuffix).empty().append(cityTwoList);
			 	$("#cityThree_"+IDSuffix).empty();
			  	$("#cityTwo_"+IDSuffix).selectpicker('refresh');
			   	$("#cityThree_"+IDSuffix).selectpicker('refresh');
			   	$("#"+IDSuffix+"CityTwo").val('');
			   	$("#"+IDSuffix+"CityThree").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
	 	  removeCityTwo(IDSuffix);
	  }
}

function changeCityThree(city1,city2,type){
	var localVar=String(city1);
	var reqUrl = '';
	var IDSuffix = 'dl';
	var listName='';
	if(type =="dl"){
		reqUrl= "/irtools/displaylocal";
		listName='disCityListThree';
	}
	else if(type == "bl"){
		reqUrl= "/irtools/belongcity";
		IDSuffix="bl";
		listName='belongCityListThree';
	}
	if(localVar != "" && city2 != ""){
      	jQuery.ajax({
       		type:"post",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:{"city2":city2,"city1":localVar},
        	success:function(data){
           	if(data!="" && data.result =="right"){
              var cityThreeList = "";
              $.each(data[listName], function(i, obj) {
                 cityThreeList = cityThreeList + "<option value='"+obj.localName+"'>"+obj.localName+"</option>";
              });
             $("#cityThree_"+IDSuffix).empty().append(cityThreeList);
             $("#cityThree_"+IDSuffix).selectpicker('refresh');
             $("#"+IDSuffix+"CityThree").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
		removeCityThree(IDSuffix);
	 }
}


function changeInfoSourceName(type,platform){
	var localVar = String(platform);
	if(type == 'add' && localVar != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/infosourceSearch",
        data:{"infoPlatform":localVar},
        success:function(data){
           if(data!="" && data.result =="right"){
          	  var sourceList = '';
              $.each(data.infoSourceList, function(i, obj) {
                 sourceList = sourceList + "<option value='"+obj.sourceName+"' title='"+obj.sourceName+"'>"+obj.sourceName+"</option>";
              });
              $("#sourceId_info").empty().append(sourceList);
               $("#sourceId_info").selectpicker('refresh');
               $("#infoSourceName").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
	}else if(type == 'remove'){
		$("#sourceId_info").empty();
		$("#sourceId_info").selectpicker('refresh');
		$("#infoSourceName").val('');
	}
}

function removeSourceTwo(){
		  $("#sourceTwo").empty();
		  $("#sourceThree").empty();
		  $("#sourceFour").empty();

		  $("#sourceTwo").selectpicker('refresh');
		  $("#sourceThree").selectpicker('refresh');
		  $("#sourceFour").selectpicker('refresh');

		  $("#flowSourceTwo").val('');
		  $("#flowSourceThree").val('');
		  $("#flowSourceFour").val('');
}

function removeSourceThree(){

		  $("#sourceThree").empty();
		  $("#sourceFour").empty();

		  $("#sourceThree").selectpicker('refresh');
		  $("#sourceFour").selectpicker('refresh');

		  $("#flowSourceThree").val('');
		  $("#flowSourceFour").val('');

}


function removeSourceFour(){

		  $("#sourceFour").empty();

		  $("#sourceFour").selectpicker('refresh');

		  $("#flowSourceFour").val('');

}




function changeSourceTwo(source1){
	if(source1 != "" ){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/flowsourcesearch",
        data:{"source1":source1},
        success:function(data){
           if(data!="" && data.result =="right"){
              	var cateTwoList = "";
              	$.each(data.flowSourceListTwo, function(i, obj) {
                cateTwoList = cateTwoList + "<option value='"+obj.source2+"' title='"+obj.source2_name+"'>"+obj.source2_name+"</option>";
             });
             $("#sourceTwo").empty().append(cateTwoList);
			 $("#sourceTwo").selectpicker('refresh');
			 $("#flowSourceTwo").val('');
			 removeSourceThree();
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
	 	 removeSourceTwo();
	  }
}

function changeSourceThree(source1,source2){
	var strSource1 = String(source1);
	var strSource2 = String(source2);

	if(strSource1 != "" && source2 != ""){
      	jQuery.ajax({
       		type:"post",
        	dataType:"json",
        	async:true,
        	url:"/irtools/flowsourcesearch",
        	data:{"source1":strSource1,"source2":strSource2},
        	success:function(data){
           	if(data!="" && data.result =="right"){
              	var cateThreeList = "";
              	$.each(data.flowSourceListThree, function(i, obj) {
              		cateThreeList = cateThreeList + "<option value='"+obj.source3+"' title='"+obj.source3_name+"'>"+obj.source3_name+"</option>";
              	});
             	$("#sourceThree").empty().append(cateThreeList);
			 	$("#sourceThree").selectpicker('refresh');
			 	$("#flowSourceThree").val('');
           	}else{
		   	  	alert("error!");
		   	}
        }
   	  });
     }else{
		removeSourceThree();
	 }
}



function changeSourceFour(source1,source2,source3){
	var strSource1 = String(source1);
	var strSource2 = String(source2);
	var strSource3 = String(source3);

	if(strSource1 != "" && source2 != "" && source3 != "" ){
      	jQuery.ajax({
       		type:"post",
        	dataType:"json",
        	async:true,
        	url:"/irtools/flowsourcesearch",
        	data:{"source1":strSource1,"source2":strSource2,"source3":strSource3},
        	success:function(data){
           	if(data!="" && data.result =="right"){
              	var cateFourList = "";
              	$.each(data.flowSourceListFour, function(i, obj) {
              		cateFourList = cateFourList + "<option value='"+obj.source4+"' title='"+obj.source4_name+"'>"+obj.source4_name+"</option>";
              	});
             	$("#sourceFour").empty().append(cateFourList);
			 	$("#sourceFour").selectpicker('refresh');
			 	$("#flowSourceFour").val('');
           	}else{
		   	  	alert("error!");
		   	}
        }
   	  });
     }else{
		removeSourceFour();
	 }
}
function removeCate(level,IDSuffix){
	if(level <= 3){
		$("#cateThree_"+IDSuffix).empty().selectpicker('refresh');
		$("#"+IDSuffix+"NewCateThree").val('');
	}
	if(level <= 2){
		  $("#cateTwo_"+IDSuffix).empty().selectpicker('refresh');
		  $("#"+IDSuffix+"NewCateTwo").val('');
	}
	if(level <= 1){
		  $("#cateOne_"+IDSuffix).empty().selectpicker('refresh');
		  $("#"+IDSuffix+"NewCateOne").val('');
	}
}

function getOptionList(dataList,type){
	var optionList='';
	$.each(dataList, function(i, obj) {
		  if(type == 1){
		  	optionList = optionList + "<option value='"+obj.cate1_name+"' title='"+obj.cate1_name+"'>"+obj.cate1_name+"</option>";
		  }else if(type == 2){
		  	optionList = optionList + "<option value='"+obj.cate2_name+"' title='"+obj.cate2_name+"'>"+obj.cate2_name+"</option>";
		  }else if(type == 3){
		  	optionList = optionList + "<option value='"+obj.cate3_name+"' title='"+obj.cate3_name+"'>"+obj.cate3_name+"</option>";
		  }

     });
    return optionList;
}

function changeCate(level,type,businessType,cate1,cate2){
	var reqUrl = '';
	var IDSuffix = 'dp';
	var paramData='';
	if(type == "dp")
		reqUrl = "/irtools/newdiscate";
	else if(type == "bc"){
		reqUrl = "/irtools/newbelongcate";
		IDSuffix="bc";
	}
	var isBiz = $("#isBiz").val();
	if(level == 3){
		paramData = {"cate1":String(cate1),"cate2":String(cate2),"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}else if(level == 2){
		paramData = {"cate1":String(cate1),"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}else if(level == 1){
		paramData = {"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}

      	jQuery.ajax({
      		type:"POST",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:paramData,
        	success:function(data){
          	if(data!="" && data.result =="right"){
          		var cateList='';
				if(level == 3){
					if(type == "dp")
						cateList = getOptionList(data.disCateListThree,3);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListThree,3);
					$("#cateThree_"+IDSuffix).empty().append(cateList).selectpicker('refresh');
				}else if(level == 2){
					if(type == "dp")
						cateList = getOptionList(data.disCateListTwo,2);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListTwo,2);
					$("#cateTwo_"+IDSuffix).empty().append(cateList).selectpicker('refresh');
					removeCate(3,IDSuffix);
				}else if(level == 1){
					if(type == "dp")
						cateList = getOptionList(data.disCateListOne,1);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListOne,1);
					$("#cateOne_"+IDSuffix).empty().append(cateList);
					$("#cateOne_"+IDSuffix).selectpicker('refresh');
					removeCate(2,IDSuffix);
				}
           }else{
		   	  alert("error!");
		   }
        }
   	  });
}




function changeJxedtSource1(type,source1){
	var source1Val = String(source1);
	if(type == 'add' && source1Val != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/jxedtSourceSearch",
        data:{"source1":source1Val,"pathId":$("#pathId").val()},
        success:function(data){
           if(data!="" && data.result =="right"){
          	  var sourceList = '';
              $.each(data.jxedtSourceTwoList, function(i, obj) {
                 sourceList = sourceList + "<option value='"+obj.source2+"' title='"+obj.source2+"'>"+obj.source2+"</option>";
              });
              $("#jxedtSourceTwo_mul").empty().append(sourceList);
              $("#jxedtSourceTwo_mul").selectpicker('refresh');
              $("#jxedtSourceTwo").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
	}else if(type == 'remove'){
		$("#jxedtSourceTwo_mul").empty();
        $("#jxedtSourceTwo_mul").selectpicker('refresh');
		$("#jxedtSourceTwo").val('');
	}
}

function showCitySelect(cityselectid){
  $(cityselectid).hide();
  document.getElementById('CitySelect').style.display='inline';
}
  /**城市控件**/
 $("select[compType='city']").on('change', function(){
    var selectType=$(this).attr('type');
    var selectName=$(this).attr('name');
    var selectLevel=parseInt($(this).attr('level'));
    if(selectLevel==1)
    {
       var selected = $(this).find("option:selected").val();
       var activeselected=$(this).parent().parent().find('.active.selected').attr('rel');
        if(typeof(activeselected)=="undefined")
        {
           var unactiveselected=$(this).parent().parent().find('.active').attr('rel');
              if(unactiveselected==0)
              {
                unsetCitySpe(zhiying,'cityOne_'+selectType+'');
              }else if(unactiveselected==1)
              {
                unsetCitySpe(zhongxiao,'cityOne_'+selectType+'');
              }

        }else{
            /*if(activeselected==0)
              {
                 $('#cityOne_'+selectType+'').selectpicker('deselectAll');
              }else*/
              if(activeselected==0)
              {
                setCitySpe(zhiying,'cityOne_'+selectType+'');
              }else if(activeselected==1)
              {
                setCitySpe(zhongxiao,'cityOne_'+selectType+'');
              }
        }
         if(document.getElementById('cityTwo_'+selectType+'')!=undefined)
         {
             if((selected!=undefined)&&($('#cityOne_'+selectType+'').val()!=null)&&($('#cityOne_'+selectType+'').val().length==1))
            {
               changeCityTwo(selected,selectType);
            }else
            {
                removeCityTwo(selectType);
            }
        }
     if($('#cityOne_'+selectType+'').val()!=null)
      {
        setSelectValue($(this).val(),selectType+'CityOne');
      }else
      {
        $('#'+selectType+'CityOne').val("");
      }

    }else if(selectLevel==2)
    {
         var selected = $(this).find("option:selected").val();
         var selected1=$('#cityOne_'+selectType+'').val();
         if(document.getElementById('cityThree_'+selectType+'')!=undefined)
         {
              if((selected!=undefined)&&($('#cityTwo_'+selectType+'').val().length==1))
            {
               changeCityThree(selected1,selected,selectType);
            }else
            {
                removeCityThree(selectType);
            }
         }
         if($('#cityTwo_'+selectType+'').val()!=null)
          {
            setSelectValue($(this).val(),selectType+'CityTwo');
          }else
          {
            $('#'+selectType+'CityTwo').val("");
          }
    }else if(selectLevel==3)
    {
         if($('#cityThree_'+selectType+'').val()!=null)
          {
            setSelectValue($(this).val(),selectType+'CityThree');
          }else
          {
            $('#'+selectType+'CityThree').val("");
          }
    }
 });
 /**类别控件**/
  $("select[compType='cate']").on('change', function(){
    var selectType=$(this).attr('type');
    var selectName=$(this).attr('name');
    var selectLevel=parseInt($(this).attr('level'));
    var busName=$('#businessTypeName_'+selectType).val();
    if(busName!=null&&busName.length==0)
    {
    	if($('#businessTypeName_'+selectType).find('option').length==1)
    	{
             busName=$('#businessTypeName_'+selectType).find('option')[0].value;
    	}
    }
    if(selectLevel==0){
        var selected = $(this).find("option:selected").val();
           if(document.getElementById('cateOne_'+selectType+'')!=undefined)
           {
                 if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
                {
                   changeCate(1,selectType,selected);
                }else
                {
                    removeCate(1,selectType);
                }
          }
          if($('#'+selectName).val()!=null)
            {
                setSelectValue($(this).val(),selectType+'BusinessTypeName');
            }else
           {
            $('#'+selectType+'BusinessTypeName').val("");
           }

    }else if(selectLevel==1)
    {
       var selected = $(this).find("option:selected").val();
       if(document.getElementById('cateTwo_'+selectType+'')!=undefined)
       {
             if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
            {
               changeCate(2,selectType,busName,selected);
            }else
            {
               removeCate(2,selectType);
            }
      }
      if($('#'+selectName).val()!=null)
        {
            setSelectValue($(this).val(),selectType+'NewCateOne');
        }else
       {
        $('#'+selectType+'NewCateOne').val("");
       }

    }else if(selectLevel==2)
    {
         var selected = $(this).find("option:selected").val();
         var cate1 = $('#cateOne_'+selectType).val();
         if(document.getElementById('cateThree_'+selectType+'')!=undefined)
         {
              if((selected!=undefined)&&($('#cateTwo_'+selectType+'').val().length==1))
            {
                changeCate(3,selectType,busName,cate1,selected);
            }else
            {
                removeCate(3,selectType);
            }
         }
         if($('#cateTwo_'+selectType+'').val()!=null)
          {
            setSelectValue($(this).val(),selectType+'NewCateTwo');
          }else
          {
            $('#'+selectType+'NewCateTwo').val("");
          }
    }else if(selectLevel==3)
    {
         if($('#cateThree_'+selectType+'').val()!=null)
          {
            setSelectValue($(this).val(),selectType+'NewCateThree');
          }else
          {
            $('#'+selectType+'NewCateThree').val("");
          }
    }
 });
  /**来源控件**/
  $("select[compType='source']").on('change', function(){
    var selectName=$(this).attr('name');
    var selectLevel=parseInt($(this).attr('level'));
    if(selectLevel==1){
            var selected = $(this).find("option:selected").val();
               if(document.getElementById('sourceTwo')!=undefined)
               {
                     if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
                    {
                       changeSourceTwo(selected);
                    }else
                    {
                       removeSourceTwo();
                    }
              }
              if($('#'+selectName).val()!=null)
                {
                    setSelectValue($(this).val(),'flowSourceOne');
                }else{
                $('#flowSourceOne').val("");
               }

    }else if(selectLevel==2)
    {
           var selected = $(this).find("option:selected").val();
           var source1=$('#sourceOne').val();
               if(document.getElementById('sourceThree')!=undefined)
               {
                     if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
                    {
                       changeSourceThree(source1,selected);
                    }else
                    {
                       removeSourceThree();
                    }
              }
              if($('#'+selectName).val()!=null)
                {
                    setSelectValue($(this).val(),'flowSourceTwo');
                }else{
                $('#flowSourceTwo').val("");
               }

    }else if(selectLevel==3)
    {
         var selected = $(this).find("option:selected").val();
         var source1=$('#sourceOne').val();
         var source2=$('#sourceTwo').val();
               if(document.getElementById('sourceFour')!=undefined)
               {
                     if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
                    {
                       changeSourceFour(source1,source2,selected);
                    }else
                    {
                       removeSourceFour();
                    }
              }
              if($('#'+selectName).val()!=null)
                {
                    setSelectValue($(this).val(),'flowSourceThree');
                }else{
                $('#flowSourceThree').val("");
               }
    }else if(selectLevel==4)
    {
         if($('#'+selectName).val()!=null)
          {
            setSelectValue($(this).val(),'flowSourceFour');
          }else
          {
            $('#flowSourceFour').val("");
          }
    }
 });
 /**单个控件**/
$("select[compType='normal']").on('change', function(){
        var hiddenInput = $(this).parent().find("input:hidden");
        var name= hiddenInput.attr('name');
        var select =$(this).find("option:selected").val();
        if($(this).val()!=null)
          {
               setSelectValue($(this).val(),name);
          }else{
               $('#'+name).val("");
          }
});
/**来源平台控件**/
$("select[compType='infoPlatform']").on('change', function(){
    var selectName=$(this).attr('name');
    var selected = $(this).find("option:selected").val();
       if(document.getElementById('sourceId_info')!=undefined)
       {
             if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
            {
               changeInfoSourceName('add',selected);
            }else
            {
               changeInfoSourceName("remove");
            }
      }
      if($('#'+selectName).val()!=null)
        {
            setSelectValue($(this).val(),'infoPlatform');
        }else{
        $('#infoPlatform').val("");
       }
});

/**驾校一点通来源控件**/
  $("select[compType='jxedtsource']").on('change', function(){
    var selectName=$(this).attr('name');
    var selectLevel=parseInt($(this).attr('level'));
    if(selectLevel==1){
        var selected = $(this).find("option:selected").val();
               if(document.getElementById('jxedtSourceOne_mul')!=undefined)
               {
                     if((selected!=undefined)&&($('#'+selectName).val()!=null)&&($('#'+selectName).val().length==1))
                    {
                       changeJxedtSource1('add',selected);
                    }else
                    {
                       changeJxedtSource1("remove");
                    }
              }
              if($('#'+selectName).val()!=null)
                {
                    setSelectValue($(this).val(),'jxedtSourceOne');
                }else{
                $('#jxedtSourceOne').val("");
               }

    }else if(selectLevel==2)
    {
           if($('#'+selectName).val()!=null)
          {
            setSelectValue($(this).val(),'jxedtSourceTwo');
          }else
          {
            $('#jxedtSourceTwo').val("");
          }

    }
  });

function setSelectValue(listvalues,txtvalues){
    var liststr=listvalues;
    var resulststr="";
     for(var i=0;i<liststr.length;i++)
        {
             resulststr += "'"+liststr[i]+"'"+",";
        }
     $('#'+txtvalues+'').val(resulststr.substring(0,resulststr.lastIndexOf(",")));
}
function sendgroupby(){
    if(document.getElementById("groupBy")==undefined)
    {
            return true;
    }
    var groups=$('#groupBy').val();
    if(groups=="")
    {
        alert("请选择维度！");
        if(!($($('#selectTitle .biui-add-btn')[1]).hasClass('active')))
            {
              $($('#selectTitle .biui-add-btn')[1]).click();
            }
        return false;
    }
    var newfs="";
    if(groups.indexOf(":")!=-1)
    {
        newfs=groups;
        $("#groupBy").val(newfs);
    }else{
	    groups=groups.substring(0,groups.lastIndexOf(","));

	    var groupstr=groups.split(",");
	    for(var i=0;i<groupstr.length;i++){
	                    newfs += (i+1)+ ":" + groupstr[i] + ",";
	    }
	    $("#groupBy").val(newfs.substring(0,newfs.lastIndexOf(",")));
    }
    return true;
}
function checkgroupby(){
    if(document.getElementById("groupBy")==undefined)
          return true;
    var groups=$('#groupBy').val();
    if(groups=="")
    {
        alert("请选择维度！");
        return false;
     }
    return true;
}
function clearallselect(ttt) {
            $(ttt).parent().parent().parent().parent().find('select').selectpicker('deselectAll');
            $(ttt).parent().parent().parent().parent().find('select').change();
            /*$(ttt).parent().parent().parent().parent().find('select').focus();*/
}
function bsallselect(ttt) {
            $(ttt).parent().parent().parent().parent().find('select').selectpicker('selectAll');
            $(ttt).parent().parent().parent().parent().find('select').change();
           /* $(ttt).parent().parent().parent().parent().find('select').focus();*/
}

function drilltdclick(clicktd){
            if($(clicktd).find('.add-icon').length>0)
            {
                $(clicktd).find('.add-icon')[0].click();
            }
        }

/* 延迟提示框组件 */
(function($) {
    jQuery.fn.MyTips = function (text,delTime,state) {
        var inf = {
            text: text,
            delTime: delTime
        };
        var t1 = null;
        var _this = $(this);

        $(this).mouseover(function (event) {
        	var indexid="";
            if(state==1)
            {
            	indexid=$(this).find("[type=checkbox]").attr("value");
            }else if(state==2)
            {
            	indexid=$(this).attr("tipid");
            }
            var startX = event.pageX;
            var startY = event.pageY;
            if(indexid!=undefined&&indexid!="")
            {
               inf.text="";
               currentAjax = $.ajax({
		            type:"POST",
		            dataType:"json",
		            async:true,
		            url:"/indexManager/tipsManager",
		            data:{"indexid":indexid},
		            success:function(data){
			               if(data.infoRule != ""){
				              	if(data.infoRemark==undefined)
				              	{
				              		data.infoRemark="未定义";
				              	}
                                if (inf.delTime == false) {  // 不需要延迟
                                		$('body').append('<div class="myTip"> 公式：'+data.infoRule+'</br>说明：'+data.infoRemark+'</div>');
				                		$('.myTip').css({left:startX,top:startY});
								} else {	// 需要延迟
									t1 = setTimeout(function () {
										$('body').append('<div class="myTip"> 公式：'+data.infoRule+'</br>说明：'+data.infoRemark+'</div>');
			                			$('.myTip').css({left:startX,top:startY});
									},inf.delTime*1000)
								}
						   }
			            },
			         error:function(data){
			         }
			   });
            }
        })
        $(this).mouseout(function () {
            clearTimeout(t1);
            if (currentAjax) {
            	currentAjax.abort();
            }
            $('.myTip').remove();
        })
    }
})(jQuery)
$('.checkbox-inline').MyTips("提示",false,1)
$('.divTip').MyTips("提示",false,2)


